package cn.liufuwen.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.dubbo.config.annotation.Reference;

import cn.liufuwen.entity.GoodsDTO;
import cn.liufuwen.entity.OrdersDTO;
import cn.liufuwen.entity.OrdersDetailDTO;
import cn.liufuwen.entity.UserDTO;
import cn.liufuwen.service.GoodsService;
import cn.liufuwen.service.OrdersDetailService;
import cn.liufuwen.service.OrdersService;
import cn.liufuwen.service.UserService;
import lombok.extern.java.Log;
@Log
@RestController
@RequestMapping("/orders")
public class OrdersController {
	@Reference(version = "${demo.service.version}")
	OrdersDetailService ordersDetailService;
	@Reference(version = "${demo.service.version}")
	OrdersService ordersService;
	@RequestMapping("/addorders")
	//将商品加入订单
    public int addOrders(HttpSession session,OrdersDetailDTO ordersDetailDTO) {
		//查询用户是否已有未提交订单
		UserDTO userDTO = (UserDTO)session.getAttribute("USER_SESSION_KEY");
		ordersDetailDTO.setUserId(userDTO.getId());
		int i = ordersDetailService.addGoods(ordersDetailDTO);
		return i;
	}

	@RequestMapping("/ordersInfo")
	public ModelAndView ordersInfo(ModelAndView modelAndView,HttpSession session,Map<String, Object> map) {
		UserDTO userDTO = (UserDTO)session.getAttribute("USER_SESSION_KEY");
		map.put("username", userDTO.getUsername());
		modelAndView.setViewName("orders_info");
		modelAndView.addAllObjects(map);
		return modelAndView;
	}
	@RequestMapping("/ordersList")
	public ModelAndView ordersList(ModelAndView modelAndView,HttpSession session,Map<String, Object> map) {
		UserDTO userDTO = (UserDTO)session.getAttribute("USER_SESSION_KEY");
		map.put("username", userDTO.getUsername());
		modelAndView.setViewName("orders_list");
		modelAndView.addAllObjects(map);
		return modelAndView;
	}
}